﻿Public Class DailyConsumptionVM

  Private mData As DailyConsumption

  Public Sub New(ByVal lData As DailyConsumption)
    mData = lData
  End Sub

  Public Property Consumption() As Double
    Get
      Return mData.Consumption
    End Get
    Set(ByVal value As Double)
      mData.Consumption = value
    End Set
  End Property

  Public Property DayOfYear() As Integer
    Get
      Return mData.DayOfYear
    End Get
    Set(ByVal value As Integer)
      mData.DayOfYear = value
    End Set
  End Property

  Public ReadOnly Property AverageConsumption As Double
    Get
      Return CalcConsumptionService.Instance.CalcAverageConsumptionToLast(Me)
    End Get
  End Property

  Public ReadOnly Property Duration As Double
    Get
      Return CalcConsumptionService.Instance.DurationToLast(Me).TotalHours
    End Get
  End Property

  Public ReadOnly Property Ticks() As Long
    Get
      Return (mData.DateDC.Value - (New Date)).TotalHours
    End Get
  End Property

  Public Property DateDC() As Date
    Get
      Return mData.DateDC
    End Get
    Set(ByVal value As Date)
      mData.DateDC = value
    End Set
  End Property

  Public ReadOnly Property Year() As Integer
    Get
      Return mData.Year.Value
    End Get
  End Property

  Public Property UserCode() As UserCode
    Get
      Return mData.UserCode
    End Get
    Set(ByVal value As UserCode)
      mData.UserCode = value
    End Set
  End Property

  Public Property Comment() As String
    Get
      Return mData.Comment
    End Get
    Set(ByVal value As String)
      mData.Comment = value
    End Set
  End Property

  Public Overrides Function ToString() As String
    Return String.Join(" - ", DateDC, Format(Consumption, "#.00") & " KWh") & vbTab & Format(AverageConsumption, "00.00") & vbTab & Left(Comment, 25)
  End Function

  Public Sub DeleteFromDB()
    DB.Context.DeleteObject(mData)
  End Sub

End Class
